//
//  PieChartTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/6.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class PieChartTableViewCell: UITableViewCell {
    
    var pieView:LCPieView!
    @IBOutlet weak var biaolei: UILabel!
    @IBOutlet weak var guoshulei: UILabel!
    @IBOutlet weak var shengxianlei: UILabel!
    @IBOutlet weak var titleLabel: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        self.pieView = LCPieView.init(frame: CGRect.init(x: 0, y: 50, width: UIScreen.ScreenWidth, height: 220-100))
        self.pieView.center = CGPoint.init(x: self.centerX, y: self.centerY + 10)
        self.addSubview(self.pieView)
        
    }
    
    func reloadWith(model:OrderStatisModel,type:Int){
        
        var value1:Double = 0
        var value2:Double = 0
        var value3:Double = 0
        
        if model.biao != nil   {
            value1 = model.biao.bMoney
        }
        
        if model.fruits != nil {
            value2 = model.fruits.gMoney
        }
        if model.fresh != nil {
            value3 = model.fresh.sMoney
        }
        
        let model1 = LCPieViewModel.init(value: CGFloat(value1), color: UIColor.init(hexColor: "#e76b62"), text: "标类")
        let model2 = LCPieViewModel.init(value: CGFloat(value2), color: UIColor.init(hexColor: "#79add1"), text: "果蔬类")
        let model3 = LCPieViewModel.init(value: CGFloat(value3), color: UIColor.init(hexColor: "#e9893b"), text: "生鲜类")
        self.pieView.show(withDataSource: [model1!,model2!,model3!])
        
        if type == 0 {
            // 本月
            self.titleLabel.text = "本月概况"
        }else{
            // 本周
            self.titleLabel.text = "本周概况"
        }
        
        let total = value1 + value2 + value3
        
        self.biaolei.text = "标类" + String.init(format: "%.1f", value1/total*100) + "%"
        self.guoshulei.text = "果蔬类" + String.init(format: "%.1f", value2/total*100) + "%"
        self.shengxianlei.text = "生鲜类" + String.init(format: "%.1f", value3/total*100) + "%"
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    

}
